﻿using System;
using Finance;

namespace TodoSoft.Reporting
{
	/// <summary>
	/// DateTime period report parameter
	/// </summary>
	public class PeriodReportParameter : ReportParameter
	{
		private DateTime _minValue = DateTime.MinValue;
		private DateTime _maxValue = DateTime.MaxValue;

		public PeriodReportParameter(string name) : base(name)
		{
		}

		public DateTime MinValue
		{
			get
			{
				return !string.IsNullOrEmpty(MinValueQuery)
					       ? (DateTime) (Sql.ExecuteScalar(MinValueQuery) ?? _minValue)
					       : _minValue;
			}
			set 
			{
				MinValueQuery = null;
				_minValue = value;
			}
		}

		public DateTime MaxValue
		{
			get
			{
				return !string.IsNullOrEmpty(MaxValueQuery)
					? (DateTime)(Sql.ExecuteScalar(MaxValueQuery) ?? _maxValue)
					: _maxValue;
			}
			set
			{
				MaxValueQuery = null;
				_maxValue = value;
			}
		}

	
		public string MinValueQuery;
		public string MaxValueQuery;
	}
}
